package com.ky.pro.java.rpc.hd.common.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ky.pro.java.rpc.hd.common.entity.Account;
import com.ky.pro.java.rpc.hd.common.mapper.AccountMapper;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 账户表 服务实现类
 * </p>
 *
 * @author Kevin Dummy
 * @since 2022-01-02
 */
@Service
public class AccountRepository extends ServiceImpl<AccountMapper, Account> implements IService<Account> {

    public boolean updateBalanceByAccountId(long accountId, int currency, long balanceToAdd) {
        return baseMapper.updateBalanceByAccountId(accountId, currency, balanceToAdd) > 0;
    }

    public Account findAccountRecordsByAccountIdAndCurrency(long accountId, int currency) {
        return baseMapper.selectOne(new QueryWrapper<Account>()
                .eq("account_id", accountId)
                .eq("currency", currency));
    }

}
